//cookie plugins
jQuery.cookie = function (name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        var path = options.path ? '; path=' + options.path : '';
        var domain = options.domain ? '; domain=' + options.domain : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
$(".search-box").addClass("search-box1");
// low verison ie broswer
$("#sou").click(function() {
	var word = $("input[name=q]").val();
	if(word == '') {
		$("#search-input").val(search_word);
	}
	$('#search form').submit();
	$("#search-input").animate({
		width:'250px',
		paddingLeft:'10px'
	});
	$(this).hide();
	$("#sousuo").show();
	$("#search-input").attr("placeholder",search_word);
});
$("#search-input").focus(function(){
	$(this).animate({
		width:'250px'
	});
	$("#sousuo").show();
	$("#search-input").attr("placeholder","请输入关键词");
})
$(document).mouseup(function(e){
	var _con = $(".search-box"); 
	if(!_con.is(e.target) && _con.has(e.target).length === 0){
		$("#search-input").animate({
			width:'140px'
		});
		$("#search-input").val(search_word);
		$("#sousuo").hide();
		$("#sou").show();
		$("#search-input").attr("placeholder",search_word);
	}
});
// search check 
$("#sousuo").click(function(event) {
	var value = $("input[name=q]").val();
	if (value == "") {
		$("#search-input").val(search_word);
		$('#search form').submit();
		//event.preventDefault();
	} else {
		$('#search form').submit();
	}
});

$("#clicksou").click(function(event) {
	var value = $("input[name=q]").val();
	// if (value == "") {
	// 	event.preventDefault();
	// }else {
	// }
});

function formsub() {
	var value = $("input[name=q]").val();
	if (value == "") {
		return false;
	} else {
		return true;
	}
}
//function moreshowHandle()
function moreshowHandle() {
	var show = 0;
	$("#more").mousemove(function() {
		show = 1;
		$("#detail").css("display", "block");
	});
	$("#more").mouseout(function(obj) {
	show = 0;
	setTimeout(function() {
		if (show == 0) {
			$("#detail").css("display", "none");
		}
	}, 500);
});
$("#detail").mousemove(function() {
	show = 1;
	$("#detail").css("display", "block");
});
$("#detail").mouseout(function(obj) {
	show = 0;
	setTimeout(function() {
		if (show == 0) {
			$("#detail").css("display", "none");
			}
		}, 500);
	});
}
moreshowHandle();
// 展示频道列表
function channelHandle() {
	var isShow = 0;
	$("#bbs-channel").mousemove(function() {
		isShow = 1;
		$("#channel-box").css("display", "block");
	});
	$("#bbs-channel").mouseout(function(obj) {
	isShow = 0;
	setTimeout(function() {
		if (isShow == 0) {
			$("#channel-box").css("display", "none");
		}
	}, 500);
});
$("#channel-box").mousemove(function() {
	isShow = 1;
	$("#channel-box").css("display", "block");
});
$("#channel-box").mouseout(function(obj) {
	isShow = 0;
	setTimeout(function() {
		if (isShow == 0) {
			$("#channel-box").css("display", "none");
			}
		}, 500);
	});
}
channelHandle()

function commonHeadercheckUserLoginInfo(){
    // var username = jQuery.cookie("accessToken");
    // var uid=jQuery.cookie("uid");
    // if(username){
    // 	$("#username").html(username + '<b style="margin-left:5px;" class="j-bottom"></b>');
	// 	$(".user-nologin").hide();
    // 	$(".user-info").show();
    // }
    
    //个人中心更多信息展示
	$(".user-info").hover(function(){
		$(".user-menu").show();
	},function(){
        var timer = setTimeout(function(){
          $(".user-menu").hide();           
        },500)
        $(".user-info").mouseover(function(){
            clearTimeout(timer);
            $(".user-menu").show();
        });
    });
}
var prof=prof || '';

var search_word= '请输入关键词';
//check auto loging user
commonHeadercheckUserLoginInfo();
function zlcSetCookie(name,value,Days){
	var domain = "zhulong.com";
	Days = Days | 5*365;
	var exp = new Date(); 
	exp.setTime(exp.getTime() + Days*24*60*60*1000);
	document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString() + "; path=" + "/" + "; domain=" + domain;
}
function cookie_fromstep(n){
	zlcSetCookie('fromstep',n-0,1);
	$.getJSON('//c.zhulong.com/shownum.php?jsoncallback=?',{showtype:"fromstep"+n},function(data){});
}